package com.idanchuang.component.redis.util.pubsub;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author yjy
 * Created at 2022/2/24 9:24 下午
 */
public class HashQueue {

    private final LinkedBlockingQueue<LockSemaphore> queue = new LinkedBlockingQueue<>();

    public void add(LockSemaphore lockSemaphore) {
        queue.add(lockSemaphore);
    }

    public void remove(LockSemaphore lockSemaphore) {
        queue.remove(lockSemaphore);
    }

    public LockSemaphore poll(String key) {
        for (LockSemaphore lockSemaphore : queue) {
            if (lockSemaphore.isAlive() && lockSemaphore.getLockKey().equals(key)) {
                return lockSemaphore;
            }
        }
        return null;
    }

}
